﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AG.Editor.Core.Data;
using AG.Editor.Core;

namespace AG.Editor.TerrainUI.Controls
{
    public partial class AGTerrainPreviewPanel : UserControl
    {
        private AGTerrain _terrain;
        private AGModel _model;

        public AGTerrainPreviewPanel()
        {
            InitializeComponent();
        }

        public void SetTerrain(AGTerrain terrain)
        {
            _terrain = terrain;
            _model = AGTools.Current.ModelStore.GetModel(AGEContext.Current.EProject, AGEContext.Current.EProject.GetModelRef(terrain.ModelUniqueId));

            string modelFolder = string.Format("{0}{1}\\", AGEContext.Current.EProject.GetFolderModels(), _model.UniqueId);

            flowLayoutPanel1.Controls.Clear();
            for (int index = 0; index < _model.Actions.Count; index++)
            {
                AGAction action = _model.Actions[index];
                for (int dirIndex = 0; dirIndex < action.Directions.Count; dirIndex++)
                {
                    AGDirection direction = action.Directions[dirIndex];
                    for (int fIndex = 0; fIndex < direction.Frames.Count; fIndex++)
                    {
                        AGFrame frame = direction.Frames[fIndex];
                        PictureBox picBox = new PictureBox();
                        picBox.Image = new Bitmap(string.Format("{0}{1}", modelFolder, frame.ImageFileName));
                        picBox.SizeMode = PictureBoxSizeMode.Normal;
                        flowLayoutPanel1.Controls.Add(picBox);
                    }
                }
            }
        }
    }
}
